<template>
  <div class="login">
    <!-- <el-row :gutter="20"> -->
    <el-col :span="8" :offset="8">
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <h1>小U商城后台</h1>
        <el-form-item label="" prop="username">
          <el-input placeholder="请输入内容" v-model="ruleForm.username">
        <template slot="prepend"><i class="el-icon-user"></i></template>
          </el-input>
          <!-- <el-input v-model="ruleForm.username"></el-input> -->
        </el-form-item>
        <el-form-item label="" prop="password">
         <el-input placeholder="请输入内容" v-model="ruleForm.password" show-password>
          <template slot="prepend"><i class="el-icon-lock"></i></template>
          </el-input>
          <!-- <el-input v-model="ruleForm.password"></el-input> -->
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('ruleForm')"
            >立即登录</el-button
          >
        </el-form-item>
      </el-form>
    </el-col>
    <!-- </el-row> -->
  </div>
</template>

<script>
export default {
  data() {
    return {
      ruleForm: {
        username: "",
        password: "",
      },
      //校验规则
      rules: {
        username: [
          { required: true, message: "请输入用户名", trigger: "blur" },
          {
            min: 3,
            max: 15,
            message: "长度在 3 到 15 个字符",
            trigger: "blur",
          },
        ],
        password: [
          { required: true, message: "请输入密码", trigger: "blur" },
          {
            min: 3,
            max: 15,
            message: "长度在 3 到 15 个字符",
            trigger: "blur",
          },
        ],
      },
    };
  },
  methods: {
    submitForm() {
      // this.$refs.ruleForm 找到要校验的表单
      // validate element ui 中自带的检验表单的函数
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          // alert("submit!");
          this.$http.post('/userlogin',this.ruleForm)
            .then(res =>{
              console.log(res);
            })
            .catch(err =>{
              console.log(err);
            })
        } else {
          return false;
        }
      });
    },
  },
};
</script>

<style>
.login {
  width: 100vw;
  height: 100vh;
  background-image: url("../assets/cts-loginbg.jpeg");
  background-size: cover;
}
/* .el-form.demo-ruleForm{
  background-color: #fff;
} */
.el-col.el-col-8.el-col-offset-8{
  width: 560px;
  height: 368px;
  margin-top: 14%;
    background-color: #fff;
    box-shadow: 0 0 30px black;
}
h1{
  width: 244px;
  text-align: center;
  padding-top: 57px;
  padding-bottom: 38px;
  color: #fb6d49;
  margin: auto;
}
.login .el-button--primary{
  width: 390px;
  background-color: #fb6d49;
  border-color:#fb6d49;
}
.el-form-item__content{
    width: 390px;
  
}
</style>